package cn.bocweb.spinning.view.forun;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.SocietyBean;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 16/3/14.
 */
public class ForunSocialAdapter extends MyAdapter<SocietyBean.DataBean> {

    List<Integer> colorList;

    public ForunSocialAdapter(Context context, List<SocietyBean.DataBean> list) {
        super(context, list);
        initColorList();

    }



    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_forun_social, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mForunSocialTitle.setText(list.get(position).getTitle());
        holder.mForunSocialContent.setText(list.get(position).getContent());
        holder.mForunSocialHistory.setText(list.get(position).getAll());
        holder.mForunSocialToday.setText(list.get(position).getToday());
        int color_bg = position % colorList.size();
        holder.mForunSocialTitleLayout.setBackgroundResource(colorList.get(color_bg));
        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.forun_social_title)
        TextView mForunSocialTitle;
        @Bind(R.id.forun_social_title_layout)
        RelativeLayout mForunSocialTitleLayout;
        @Bind(R.id.forun_social_content)
        TextView mForunSocialContent;
        @Bind(R.id.forun_social_today)
        TextView mForunSocialToday;
        @Bind(R.id.forun_social_history)
        TextView mForunSocialHistory;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


    private void initColorList() {
        colorList = new ArrayList<>();
        colorList.add(R.drawable.society_1);
        colorList.add(R.drawable.society_2);
        colorList.add(R.drawable.society_3);
        colorList.add(R.drawable.society_4);
        colorList.add(R.drawable.society_5);
        colorList.add(R.drawable.society_6);
        colorList.add(R.drawable.society_7);
        colorList.add(R.drawable.society_8);
        colorList.add(R.drawable.society_9);
        colorList.add(R.drawable.society_10);
        colorList.add(R.drawable.society_11);
        colorList.add(R.drawable.society_12);
        colorList.add(R.drawable.society_13);
        colorList.add(R.drawable.society_14);
        colorList.add(R.drawable.society_15);
    }
}
